<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>退款申请表</title>
    <link rel="stylesheet" href="http://47.100.102.177:8080/app/css/common/bootstrap.min.css">
    <link rel="stylesheet" href="../../../boot/plugin/download/font_2801350_hw9pyy8c125/iconfont.css">    <script src="http://47.100.102.177:8080/app/js/common/jquery-1.12.4.js"></script>
    <!-- 必须先引入vue，  后使用element-ui -->
    <script src="../../../boot/plugin/element/vue.js"></script>
    <!--引入 element-ui 的样式，-->
    <link rel="stylesheet" href="../../../boot/plugin/element/element.css">
    <!-- 引入element 的组件库-->
    <script src="../../../boot/plugin/element/element.js"></script>
    <style>
        th {
            text-align: center;
        }
    </style>
</head>

<body>
    <div style="width: 100%;height: 20px;"></div>
    <form class="form-inline" style="text-align: center;">
        <div class="form-group">
            <label for="orderID">订单id</label>
            <input type="text" class="form-control" id="orderID" placeholder="请输入订单ID">
            <label for="userID">用户id</label>
            <input type="text" class="form-control" id="userID" placeholder="请输入用户ID">
        </div>
        <button type="button" class="btn btn-default" onclick="findBack()"><i class="iconfont"
                style="font-size: 14px;color: #3E8EF7;">&#xe660;</i></button>
        <button type="button" class="btn btn-info" onclick="flash()">刷新</button>
    </form>
    <div style="width: 100%;height: 20px;"></div>
    <table class="table table-bordered" style="text-align: center;">
        <thead id="th">
            <tr>
                <th><input type="checkbox" id="all"></th>
                <th>订单id(订单号)</th>
                <th>商品id</th>
                <th>商品类型</th>
                <th>用户id</th>
                <th>申请时间</th>
                <th>退款原因</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody id="tb">

        </tbody>
    </table>
    <div style="float: right;margin-right: 20px;">
        <div style="float: left;height: 80px;line-height: 80px;margin-right: 20px;" id="pageNum">共&nbsp;<span style="color: red">${allNum}</span>&nbsp;条记录&nbsp;&nbsp;</div>
        <div style="float: left;height: 80px;line-height: 80px;margin-right: 20px;">&nbsp;<span style="color: red">12</span>&nbsp;条&nbsp;/&nbsp;页</div>
        <div id="app" style="float: left;" onclick="page()">
            <el-pagination background layout="prev, pager, next" :total="${page}*10" style="margin-top: 23px;">
            </el-pagination>
        </div>
    </div>
    <script type="text/javascript">
        new Vue().$mount('#app');

        let back_list = ${backList};
        let tb = document.getElementById("tb");
        let str = "";
        for (let i = 0; i < back_list.length; i++) {
            str += '<tr>';
            str += '<td><input type="checkbox" name="cks"></td>';
            str += '<td>' + back_list[i].orderId + '</td>';
            str += '<td>' + back_list[i].shopId + '</td>';
            str += '<td>' + back_list[i].shopType + '</td>';
            str += '<td>' + back_list[i].userId + '</td>';
            str += '<td>' + back_list[i].backTime + '</td>';
            str += '<td>' + back_list[i].backReason + '</td>';
            str += '<td>';
            str += '<button class="btn-link" type="button" onclick="pass(\'' + back_list[i].orderListId + '\')">通过</button>';
            str += '<button class="btn-link" type="button" onclick="fail(\'' + back_list[i].orderListId + '\')">回绝</button>';
            str += '</td>';
            str += '</tr>';
        }
        tb.innerHTML = str;

        function page() {
            let active = document.getElementsByClassName("active")[0];
            let param = "nowPage="+parseInt(active.innerText);
            $.get('/boot/admin/getNowBack',param,function (res) {
                back_list = res;
                str = "";
                for (let i = 0; i < back_list.length; i++) {
                    str += '<tr>';
                    str += '<td><input type="checkbox" name="cks"></td>';
                    str += '<td>' + back_list[i].orderId + '</td>';
                    str += '<td>' + back_list[i].shopId + '</td>';
                    str += '<td>' + back_list[i].shopType + '</td>';
                    str += '<td>' + back_list[i].userId + '</td>';
                    str += '<td>' + back_list[i].backTime + '</td>';
                    str += '<td>' + back_list[i].backReason + '</td>';
                    str += '<td>';
                    str += '<button class="btn-link" type="button" onclick="pass(\'' + back_list[i].orderListId + '\')">通过</button>';
                    str += '<button class="btn-link" type="button" onclick="fail(\'' + back_list[i].orderListId + '\')">回绝</button>';
                    str += '</td>';
                    str += '</tr>';
                }
                tb.innerHTML = str;
            })
        }

        function findBack(){
            let buyId = document.getElementById("orderID").value;
            let userId = document.getElementById("userID").value;
            $.get('/boot/admin/findBack',{buyId:buyId,userId:userId},function (res){
                str = "";
                if (res!=null&&res[0]!=null){
                    back_list = res;
                    for (let i = 0; i < back_list.length; i++) {
                        str += '<tr>';
                        str += '<td><input type="checkbox" name="cks"></td>';
                        str += '<td>' + back_list[i].orderId + '</td>';
                        str += '<td>' + back_list[i].shopId + '</td>';
                        str += '<td>' + back_list[i].shopType + '</td>';
                        str += '<td>' + back_list[i].userId + '</td>';
                        str += '<td>' + back_list[i].backTime + '</td>';
                        str += '<td>' + back_list[i].backReason + '</td>';
                        str += '<td>';
                        str += '<button class="btn-link" type="button" onclick="pass(\'' + back_list[i].orderListId + '\')">通过</button>';
                        str += '<button class="btn-link" type="button" onclick="fail(\'' + back_list[i].orderListId + '\')">回绝</button>';
                        str += '</td>';
                        str += '</tr>';
                    }
                }else {
                    str += '<tr><td colspan="8">查询为空</td></tr>';
                }
                tb.innerHTML = str;
            })
        }

        function pass(orderListId){
            if (parseInt(${admin.powerId})==1 || parseInt(${admin.powerId})==2){
                if(confirm("你确定执行此操作吗?")) {
                    $.get('/boot/admin/passBack',{orderListId:orderListId},function (res){
                        if (res.code=="200") {
                            alert(res.msg);
                            location.reload();
                        }
                    })
                }
            }else {
                alert("对不起!只有Ⅰ,Ⅱ级管理员才能执行此操作!!!")
            }
        }
        function fail(orderListId){
            if (parseInt(${admin.powerId})==1 || parseInt(${admin.powerId})==2){
                if(confirm("你确定执行此操作吗?")) {
                    $.get('/boot/admin/failBack',{orderListId:orderListId},function (res){
                        if (res.code=="200") {
                            alert(res.msg);
                            location.reload();
                        }
                    })
                }
            }else {
                alert("对不起!只有Ⅰ,Ⅱ级管理员才能执行此操作!!!")
            }
        }

        function flash(){
            location.reload();
        }

        $(function() {
            //通过点击最上面的全选框，它的选中状态决定后面复选框的选中状态
            $("#all").click(function() {
                console.log($(this).prop("checked"));
                console.log($("#tb input"));
                $("#tb input").prop("checked", $(this).prop("checked"));
            });

            //后面的复选框点击后，判断是否全部都选中，如果都选中，最上面的全选框自动勾上
            $("#tb input").click(function() {
                console.log($("#tb input:checked")); //选中的元素
                if ($("#tb input:checked").length == $("#tb input").length) {
                    $("#all").prop("checked", true);
                } else {
                    $("#all").prop("checked", false);
                }
            });
            $("#close").click(function() {
                $(".bg").css("display", "none");
            });
            $("#close-add").click(function() {
                $(".bg-add").css("display", "none");
            });

            $("#orderID").bind("input propertychange", function() {
                var text = $("#orderID").val();
                if (text != '') { //若输入框1的内容不为空，则输入框2不可用
                    $("#userID").attr("disabled", "disabled"); //设置输入框2不可用
                } else {
                    $("#userID").removeAttr("disabled"); //移除不可用的属性
                }
            })
            $("#userID").bind("input propertychange", function() {
                var text = $("#userID").val();
                if (text != '') { //若输入框1的内容不为空，则输入框2不可用
                    $("#orderID").attr("disabled", "disabled"); //设置输入框2不可用
                } else {
                    $("#orderID").removeAttr("disabled"); //移除不可用的属性
                }
            })
        });
    </script>
</body>

</html>